package com.shrct.businessprocess.project.impl;

import com.google.common.base.Objects;
import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.impl.RCEmployeeImpl;
import com.shrct.businessprocess.project.RCCostShareYearConfig;
import com.shrct.businessprocess.project.RCCostShareYearConfigItem;
import com.shrct.businessprocess.project.impl.RCCostShareYearConfigImpl;
import com.shrct.businessprocess.project.proxy.RCCostShareYearConfigItemProxy;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCCOSTSHAREYEARCONFIGITEM_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rccostshareyearconfigitem")
public class RCCostShareYearConfigItemImpl extends BaseModelObject implements RCCostShareYearConfigItem {
  public RCCostShareYearConfigItemImpl() {
    super();
  }
  
  public RCCostShareYearConfigItemImpl(final RCCostShareYearConfig config) {
    super();
    this.config = config;
  }
  
  @JoinColumn(name = "config_id")
  @ManyToOne(targetEntity = RCCostShareYearConfigImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCCostShareYearConfig config;
  
  public RCCostShareYearConfig getConfig() {
    return this.config;
  }
  
  public RCCostShareYearConfigItem setConfig(final RCCostShareYearConfig config) {
    this.config = config;
    return this;			
    
  }
  
  @JoinColumn(name = "shareTarget_id")
  @ManyToOne(targetEntity = RCEmployeeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCEmployee shareTarget;
  
  public RCEmployee getShareTarget() {
    return this.shareTarget;
  }
  
  public RCCostShareYearConfigItem setShareTarget(final RCEmployee shareTarget) {
    this.shareTarget = shareTarget;
    return this;			
    
  }
  
  private Double totalCost = Double.valueOf(0d);
  
  public Double getTotalCost() {
    return this.totalCost;
  }
  
  public RCCostShareYearConfigItem setTotalCost(final Double totalCost) {
    this.totalCost = totalCost;
    return this;			
    
  }
  
  private Double shareRate = Double.valueOf(1.0d);
  
  public Double getShareRate() {
    return this.shareRate;
  }
  
  public RCCostShareYearConfigItem setShareRate(final Double shareRate) {
    this.shareRate = shareRate;
    return this;			
    
  }
  
  public void update(final Procedure1<? super RCCostShareYearConfigItem> updater) {
    updater.apply(this);
    this.checkValid();
  }
  
  public void checkValid() {
    boolean _notEquals = (!Objects.equal(this.shareTarget, null));
    Validates.Assert(_notEquals, "\u644A\u9500\u5458\u5DE5\u5FC5\u987B\u8BBE\u7F6E");
    boolean _notEquals_1 = (!Objects.equal(this.totalCost, null));
    Validates.Assert(_notEquals_1, "\u644A\u9500\u5458\u5DE5\u8D39\u7528\u5FC5\u987B\u8BBE\u7F6E");
    boolean _notEquals_2 = (!Objects.equal(this.shareRate, null));
    Validates.Assert(_notEquals_2, "\u644A\u9500\u5458\u5DE5\u5206\u644A\u6BD4\u4F8B\u5FC5\u987B\u8BBE\u7F6E");
  }
  
  public static RCCostShareYearConfigItem create(final RCCostShareYearConfig config, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.project.RCCostShareYearConfigItem rCCostShareYearConfigItem = new com.shrct.businessprocess.project.impl.RCCostShareYearConfigItemImpl(
    	config
    );
    objectFactory.create(rCCostShareYearConfigItem);
    return rCCostShareYearConfigItem;			
    
  }
  
  public static RCCostShareYearConfigItem createRCCostShareYearConfigItemImpl(final RCCostShareYearConfig config, final IObjectFactory objectFactory, final Procedure1<RCCostShareYearConfigItem> init) {
    com.shrct.businessprocess.project.RCCostShareYearConfigItem rCCostShareYearConfigItem = new com.shrct.businessprocess.project.impl.RCCostShareYearConfigItemImpl(
    	config
    );
    objectFactory.create(rCCostShareYearConfigItem);
    init.apply(rCCostShareYearConfigItem);
    
    return rCCostShareYearConfigItem;			
    
  }
  
  public RCCostShareYearConfigItemProxy toProxy() {
    com.shrct.businessprocess.project.proxy.RCCostShareYearConfigItemProxy proxy = new com.shrct.businessprocess.project.proxy.RCCostShareYearConfigItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
